package com.cjw.controller.resourceManage;

import com.cjw.pojo.dto.database.PageDTO;
import com.cjw.pojo.dto.resourceManage.ResourceListDTO;
import com.cjw.pojo.dto.resourceManage.RoleListDTO;
import com.cjw.pojo.dto.resourceManage.RoleSimpleDTO;
import com.cjw.pojo.query.PageQuery;
import com.cjw.pojo.query.resourceManage.AddRole;
import com.cjw.pojo.query.resourceManage.RoleQuery;
import com.cjw.pojo.query.resourceManage.UpdateRole;
import com.cjw.service.resourceManage.RoleManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author : cjw
 * @date: : 2022/3/26 16:31
 * @description : 角色资源
 */
@RestController
@RequestMapping("/admin/roleManage")
@Api("角色资源")
public class RoleManageController {
    @Autowired
    private RoleManageService roleService;

    @PostMapping("/add")
    @ApiOperation("添加角色")
    public Boolean add(@RequestBody @Valid AddRole addRole) {
        return roleService.add(addRole);
    }

    @PostMapping("/delete")
    @ApiOperation("删除角色")
    public Boolean delete(Long id) {
        return roleService.delete(id);
    }

    @PostMapping("/update")
    @ApiOperation("修改角色")
    public Boolean update(@RequestBody @Valid UpdateRole updateRole) {
        return roleService.update(updateRole);
    }

    @PostMapping("/list")
    @ApiOperation("分页获取全部角色列表")
    public PageDTO<List<RoleListDTO>> list(@RequestBody RoleQuery roleQuery) {
        return roleService.list(roleQuery);
    }

    @GetMapping("/all")
    @ApiOperation("获取全部角色")
    public List<RoleSimpleDTO> all() {
        return roleService.all();
    }

    @GetMapping("/resource/list")
    @ApiOperation("获取全部资源列表")
    public List<ResourceListDTO> resourceList() {
        return roleService.resourceList();
    }

    @GetMapping("/resource/byRoleId")
    @ApiOperation("获取资源列表通过角色id")
    public AddRole resourceByRoleId(Long id) {
        return roleService.resourceByRoleId(id);
    }

    @GetMapping("/getRole")
    @ApiOperation("获取用户角色")
    public String getRole(Long id) {
        return roleService.getRole(id);
    }
}
